package com.googlecode.ducktype;

import java.lang.reflect.Proxy;

public class StandardProxyFactory implements ProxyFactory {

    @SuppressWarnings("unchecked")
    public <T> T proxyFor(Object objectToCoerce, Class<T> iface) {
        if (!iface.isInterface()) {
            throw new IllegalArgumentException("Must use interface when using StandardProxyFactory");
        }
        return (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class[] { iface },
                new CoercedProxy(objectToCoerce));
    }

    public static ProxyFactory getInstance() {
        return new StandardProxyFactory();
    }
    
    protected StandardProxyFactory() { }

}
